package com.jy.show.common;


/**
 * 标准返回对象
 * @param <T>
 *     {"code":200,"msg":"","data":xxxxx}
 */
public class ResultCommon<T> {

    private int code;

    private String msg;

    private T data;

    private ResultCommon(){};

    private ResultCommon(int code, String msg){
        this.code = code;
        this.msg = msg;
    }
    private ResultCommon(int code, String msg, T data){
        this(code,msg);
        this.data=data;
    }

    public static  ResultCommon success(ResultCode resultCode){
        ResultCommon<Object> resultCommon = new ResultCommon<>(resultCode.getCode(), resultCode.getMsg());
       return resultCommon;
    }

    public static  <T>ResultCommon<T> success(ResultCode resultCode, T data){
        ResultCommon success = success(resultCode);
        success.setData(data);
        return success;
    }

    public static  ResultCommon fail(ResultCode resultCode){
        return success(resultCode);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
